#include <iostream>
#include <unistd.h>
#include <sys/types.h>

using namespace std;

int main()
{
	int i = 1;
	//cout<< "父进程开始运行,PID:" << getpid() << endl;
	//fork();
	//cout<< "进程开始运行,PID:" << getpid() << endl;
	//while(0)
	//{
	//	cout << "hello linux" << i << endl;
	//	sleep(1);
	//}
	
	pid_t id = fork();
	
	if(id < 0)
	{
		perror("fork fail");
		return 1;
	}
	else if(id == 0)
	{
		while(i++)
		{
			sleep(1);
			cout << i <<"我是子进程!,PID为:"<<getpid()<<"父进程PPID为:"<<getppid()<<endl;
		}
	}
	else
	{
		while(i++)
		{	
			sleep(1);
			cout << i <<"我是父进程!,PID为:"<<getpid()<<"父进程PPID为:"<<getppid()<<endl;
		}
	}
	

	return 0;
}

